import {createRouter,createWebHistory,RouteRecordRaw} from "vue-router"
import https from "../utils/https"

//页面引入路径报错 

// 在vite-env.d.ts 中添加代码
// declare module "*.vue" {
//     import { App, defineComponent } from "vue";
//     const component: ReturnType<typeof defineComponent> & {
//         install(app: App): void;
//     };
//     export default component;
// }


// let pagerouter = [];
// //请求后端的路由页面
// https.get("/api/page",{params:{status:"publish"}}).then(res=>{
//     console.log(res.data.data[0],"router res")
//     if(res.status==200){
//         pagerouter = res.data.data[0]
//     }
// })





export const routes:Array<RouteRecordRaw> = [
    {
        path:"/",
        name:"default",
        component:()=>import("../view/Default.vue"),
        meta:{
            name:"首页"
        },
        children:[
            {
                path:"/",
                redirect:"/home"
            },{
                path:"/home",
                name:"home",
                component:()=>import("../view/Home.vue"),
                meta:{
                    name:"文章"
                }
            },
            {
                path:"/archives",
                name:"archives",
                component:()=>import("../view/Archives.vue"),
                meta:{
                    name:"归类"
                }
            },{
                path:"/knowledge",
                name:"knowledge",
                component:()=>import("../view/Knowledge.vue"),
                meta:{
                    name:"知识小测"
                }
            },{
                path:"/pages/:path",
                name:"pages",
                component:()=>import("../view/Pages.vue"),
                meta:{
                    name:"页面"
                }
            },{
                path:"/archives/:id",
                name:"archivesdetail",
                component:()=>import("../view/ArchiveDetail.vue"),
                meta:{
                    name:"详情页"
                }
            },{
                path:"/category/:id",
                name:"category",
                component:()=>import("../view/Category.vue"),
                meta:{
                    name:"分类页"
                }
            },{
                path:"/tags/:id",
                name:"tags",
                component:()=>import("../view/tags.vue"),
                meta:{
                    name:"标签页"
                }
            },{
                path:"/knowdetail/:id",
                name:"knowdetail",
                component:()=>import("../view/Knowdetail.vue"),
                meta:{
                    name:"知识小测详情页"
                }
            }
        ]
    },{
        path:"/:catchAll(.*)",
        name:"404",
        component:()=>import("../view/Error.vue"),
        meta:{
            name:"404"
        }
    }
]

// let routerList = async () =>{
//     let res = await https.get("/api/page",{params:{status:"publish"}});
//     if(res.status == 200){
//         return 
//     }
// }
// routerList().then(res=>{
//     console.log(res,"list")
// })

 const router =  createRouter({
    history:createWebHistory(),
    routes
 })

export default router

